package com.jbp.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jbp.dao.BlackDeviceDao;
import com.jbp.model.BlackDevice;
import com.jbp.model.BlackIp;
import com.jbp.service.BlackDeviceService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import com.jbp.utils.PageUtils;
import com.jbp.utils.Query;
import java.util.Map;

/**
 * 设备黑名单(BlackDevice)表服务实现类
 * @author cc
 * @since 2020-11-06 13:59:23
 */
@Service
public class BlackDeviceServiceImpl extends ServiceImpl<BlackDeviceDao, BlackDevice> implements BlackDeviceService {
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<BlackDevice> queryWrapper = new QueryWrapper<>();
        if (params.get("id") != null){
            queryWrapper.like("id",params.get("id"));
        }
        IPage<BlackDevice> page = this.page(
                new Query<BlackDevice>().getPage(params),
                queryWrapper
        );

        return new PageUtils(page);
    }

    @Override
    public boolean isBlack(String device) {
        if(StringUtils.isEmpty(device)) {
            return false;
        }

        BlackDevice one = getOne(new QueryWrapper<BlackDevice>().eq("device", device));

        return one!=null;
    }
}